package com.liwenfeng.iostream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
 * 文件复制工具：
 * 可以复制任何文件，不涉及编码和解码
 * */
public class CopyFile {
    public static void main(String[] args) {
        new CopyFile().copy("D:/code/java/JAVA22/function2framework/src/main/java/com/liwenfeng/test.txt", "D:/code/java/JAVA22/function2framework/src/main/java/com/liwenfeng/test1.txt");
    }

    public void copy(String source, String target) {
        try (
                FileInputStream fis = new FileInputStream(source);
                FileOutputStream fos = new FileOutputStream(target)
        ) {
            byte[] readAllBytes = fis.readAllBytes();
            fos.write(readAllBytes);
            System.out.println("文件拷贝成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
